package cn.cefoc.controller;

import cn.cefoc.domain.User;
import cn.cefoc.feign.UserService;
import cn.cefoc.sentinel.getUserBlockHandlerClass;
import cn.cefoc.sentinel.getUserFallbackClass;
import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.sun.deploy.security.BlockedException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class OrderController {
    @Autowired
    private UserService userService;

    @GetMapping("/order/{id}")
    @SentinelResource(value = "user-server-getById",
            blockHandler = "getUserBlockHandler",
            blockHandlerClass = getUserBlockHandlerClass.class,
            fallback = "getUserFallback",
            fallbackClass = getUserFallbackClass.class)
    public User getUser(@PathVariable("id") Long id){
        return userService.FindUserById(id);
    }

//    // 局部限流
//    public User getUserBlockHandler(@PathVariable("id") Long id, BlockException exception){
//        return new User(-1L,"限流了","别进来了");
//    }

//    // 当前类中写熔断
//    public User getUserFallback(@PathVariable("id") Long id, Throwable throwable){
//        return new User(-1L,"熔断了哦","快断了，别进来了~~");
//    }

}
